/**
 * 题目描述
 * 一个纯数字的字符串，怎么分割使左右两部分乘积最大，返回最大的乘积
 * */

function maxProduct(numStr) {
    if (numStr === null || numStr.length === 0) {
        return 0;
    }

    let maxProd = 0;
    let maxLeft = 0;
    let maxRight = 0;
    for (let i = 1; i < numStr.length; i++) {
        const left = numStr.substring(0, i);
        const right = numStr.substring(i);
        const prod = parseInt(left) * parseInt(right);
        if (prod > maxProd) {
            maxProd = prod;
            maxLeft = left;
            maxRight = right;
        }
    }

    console.log(`${numStr} is ${maxProd}, ${maxLeft}*${maxRight}`);

    return maxProd;
}

console.log(maxProduct('12345')); // 6170
console.log(maxProduct('0000')); // 0
console.log(maxProduct('9973')); // 8757
console.log(maxProduct('10000')); // 0
console.log(maxProduct('123')); // 36
console.log(maxProduct('02984')); // 2436
console.log(maxProduct('503')); // 150
console.log(maxProduct('103')); // 30
